﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace HdipCricketClub.Models
{
       
    [MetadataType(typeof(FixtureMetaData))]
    public partial class Fixture
    {
        public Fixture ParseFormCollection(FormCollection formCollection)
        {
            string[] fixtureId = formCollection.GetValues("ScorecardFixture.fixture_Id");
            string[] teamId = formCollection.GetValues("ScorecardFixture.team_Id");
            string[] opponentId = formCollection.GetValues("ScorecardFixture.opponent_Id");
            string[] home = formCollection.GetValues("ScorecardFixture.home");
            string[] type = formCollection.GetValues("ScorecardFixture.type");
            string[] date = formCollection.GetValues("ScorecardFixture.date");
            string[] startTime = formCollection.GetValues("ScorecardFixture.start_time");
            string[] noOfPlayers = formCollection.GetValues("ScorecardFixture.no_of_players");

            Fixture fixture = new Fixture()
                            {
                                fixture_id = Int32.Parse(fixtureId[0]),
                                team_id = Int32.Parse(teamId[0]),
                                opponent_id = Int32.Parse(opponentId[0]),
                                home = bool.Parse(home[0]),
                                type = opponentId[0],
                                date = DateTime.Parse(date[0]),
                                start_time = TimeSpan.Parse(startTime[0]),
                                no_of_players = Int32.Parse(noOfPlayers[0])
                            };

            return fixture;
        }

        public void Update(FormCollection formCollection)
        {
            
        }




    }

    public class FixtureMetaData
    {
        [Required(ErrorMessage = "Type is required")]
        [Display(Name = "Type:")]
        public object type;

        [Required(ErrorMessage = "Home or Away must be specified")]
        [Display (Name = "Home Fixture:")]
        public object home;

        [Required (ErrorMessage = "Date is required")]
        [Display(Name = "Date:")]
        [DataType(DataType.Date, ErrorMessage = "Incorrect date entered")]
        public object date;

        [Required(ErrorMessage = "Start time is required")]
        [Display(Name = "Start Time:")]
        [DataType(DataType.Time, ErrorMessage = "Incorrect time entered")]
        public object start_time;

        [Required(ErrorMessage = "No of Players is required")]
        [Display(Name = "Number of Players:")]
        public object no_of_players;
                
        

    }


}